Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OPA support to the policy API's: #579

Merged
merged 3 commits into from Nov 3, 2022
Merged

Add OPA support to the policy API's: #579

merged 3 commits into from Nov 3, 2022

Conversation

mrinalirao
Copy link
Contributor

Description

Add OPA support to the go-tfe client for policy API's. OPA is still in beta phase.
This PR only contains changes to the policy API's.

For a complete list of API's that will be updated in subsequent PRs see : https://github.com/hashicorp/terraform-docs-common/pull/141/files

Updated Api's:

  • Create Policy: Adds the kind and Query options for OPA and the new enforcement_level
  • Update Policy: Adds option to update the Query
  • List Policy: List allows filtering by kind

Testing plan

Integration tests added

External links

API Docs
JIRA
API PR

Output from tests

Needs the following env vars:
TFE_ADDRESS
TFE_TOKEN
OAUTH_CLIENT_GITHUB_TOKEN
GITHUB_POLICY_SET_IDENTIFIER
Set ENABLE_BETA=1

envchain local go test -run TestPoliciesCreate_Beta -v ./... -tags=integration
=== RUN   TestPoliciesCreate_Beta
=== RUN   TestPoliciesCreate_Beta/with_valid_options_-_Sentinel
=== RUN   TestPoliciesCreate_Beta/with_no_kind
=== RUN   TestPoliciesCreate_Beta/with_valid_options_-_OPA
=== RUN   TestPoliciesCreate_Beta/when_options_has_an_invalid_name_-_OPA
=== RUN   TestPoliciesCreate_Beta/when_options_is_missing_name_-_OPA
=== RUN   TestPoliciesCreate_Beta/when_options_is_missing_query_-_OPA
=== RUN   TestPoliciesCreate_Beta/when_options_is_missing_an_enforcement
=== RUN   TestPoliciesCreate_Beta/when_options_is_missing_enforcement_path
=== RUN   TestPoliciesCreate_Beta/when_options_is_missing_enforcement_path#01
=== RUN   TestPoliciesCreate_Beta/when_options_has_an_invalid_organization
--- PASS: TestPoliciesCreate_Beta (8.12s)
    --- PASS: TestPoliciesCreate_Beta/with_valid_options_-_Sentinel (1.22s)
    --- PASS: TestPoliciesCreate_Beta/with_no_kind (1.65s)
    --- PASS: TestPoliciesCreate_Beta/with_valid_options_-_OPA (1.21s)
    --- PASS: TestPoliciesCreate_Beta/when_options_has_an_invalid_name_-_OPA (0.00s)
    --- PASS: TestPoliciesCreate_Beta/when_options_is_missing_name_-_OPA (0.00s)
    --- PASS: TestPoliciesCreate_Beta/when_options_is_missing_query_-_OPA (0.57s)
    --- PASS: TestPoliciesCreate_Beta/when_options_is_missing_an_enforcement (0.00s)
    --- PASS: TestPoliciesCreate_Beta/when_options_is_missing_enforcement_path (0.00s)
    --- PASS: TestPoliciesCreate_Beta/when_options_is_missing_enforcement_path#01 (0.00s)
    --- PASS: TestPoliciesCreate_Beta/when_options_has_an_invalid_organization (0.00s)
PASS
ok      github.com/hashicorp/go-tfe     9.270s
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]

envchain local go test -run TestPoliciesList_Beta -v ./... -tags=integration
=== RUN   TestPoliciesList_Beta
=== RUN   TestPoliciesList_Beta/without_list_options
=== RUN   TestPoliciesList_Beta/with_pagination
=== RUN   TestPoliciesList_Beta/with_search
=== RUN   TestPoliciesList_Beta/with_filter_by_kind
=== RUN   TestPoliciesList_Beta/without_a_valid_organization
--- PASS: TestPoliciesList_Beta (9.29s)
    --- PASS: TestPoliciesList_Beta/without_list_options (0.67s)
    --- PASS: TestPoliciesList_Beta/with_pagination (0.61s)
    --- PASS: TestPoliciesList_Beta/with_search (0.66s)
    --- PASS: TestPoliciesList_Beta/with_filter_by_kind (0.66s)
    --- PASS: TestPoliciesList_Beta/without_a_valid_organization (0.00s)
PASS
ok      github.com/hashicorp/go-tfe     9.446s
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]
envchain local go test -run TestPoliciesList_Beta -v ./... -tags=integration
=== RUN   TestPoliciesList_Beta
=== RUN   TestPoliciesList_Beta/without_list_options
=== RUN   TestPoliciesList_Beta/with_pagination
=== RUN   TestPoliciesList_Beta/with_search
=== RUN   TestPoliciesList_Beta/with_filter_by_kind
=== RUN   TestPoliciesList_Beta/without_a_valid_organization
--- PASS: TestPoliciesList_Beta (9.29s)
    --- PASS: TestPoliciesList_Beta/without_list_options (0.67s)
    --- PASS: TestPoliciesList_Beta/with_pagination (0.61s)
    --- PASS: TestPoliciesList_Beta/with_search (0.66s)
    --- PASS: TestPoliciesList_Beta/with_filter_by_kind (0.66s)
    --- PASS: TestPoliciesList_Beta/without_a_valid_organization (0.00s)
PASS
ok      github.com/hashicorp/go-tfe     9.446s
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]
mrinalirao@mrinalirao-V27QW1R72C go-tfe % envchain local go test -run TestPoliciesUpdate_Beta -v ./... -tags=integration
=== RUN   TestPoliciesUpdate_Beta
=== RUN   TestPoliciesUpdate_Beta/with_a_new_query
--- PASS: TestPoliciesUpdate_Beta (6.08s)
    --- PASS: TestPoliciesUpdate_Beta/with_a_new_query (3.07s)
PASS
ok      github.com/hashicorp/go-tfe     6.249s
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]

@mrinalirao mrinalirao requested a review from a team as a code owner November 2, 2022 07:00
Updated Api's:
- Create Policy: Adds the kind and Query options for OPA and enforcement_level
- Update Policy: Adds option to update the Query
- List Policy: List allows filtering by kind

Adds integration tests for the above
errors.go Outdated Show resolved Hide resolved
helper_test.go Show resolved Hide resolved
policy_set.go Outdated Show resolved Hide resolved
# Conflicts:
#	policy_set.go
glennsarti
glennsarti previously approved these changes Nov 3, 2022
policy.go Outdated Show resolved Hide resolved
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good 🎉

Uk1288
Uk1288 previously approved these changes Nov 3, 2022
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! 🥳

@mrinalirao mrinalirao merged commit 57104e8 into main Nov 3, 2022
@mrinalirao mrinalirao deleted the TF-1450-policies branch November 3, 2022 22:57
@github-actions
Copy link

github-actions bot commented Nov 3, 2022

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants